package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_setup_bank_manual_config;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_setup_bank_manual_configSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_setup_bank_manual_configService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[银行设置通用配置] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_setup_bank_manual_configServiceImpl implements IAccount_setup_bank_manual_configService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_setup_bank_manual_configClientService account_setup_bank_manual_configClientService;

    @Override
    public boolean create(Account_setup_bank_manual_config account_setup_bank_manual_config) {
        boolean bOk = false ;
        Iaccount_setup_bank_manual_config clientModel = this.convert2Model(account_setup_bank_manual_config,null);
        account_setup_bank_manual_configClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_setup_bank_manual_config);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Account_setup_bank_manual_config account_setup_bank_manual_config) {
        boolean bOk = false ;
        Iaccount_setup_bank_manual_config clientModel = this.convert2Model(account_setup_bank_manual_config,null);
        account_setup_bank_manual_configClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_setup_bank_manual_config) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Account_setup_bank_manual_config> account_setup_bank_manual_configs, int batchSize) {

        //account_setup_bank_manual_configClientService.updateBatch(account_setup_bank_manual_configs,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_setup_bank_manual_config clientModel = account_setup_bank_manual_configClientService.createModel();
        clientModel.setId(id);
        account_setup_bank_manual_configClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Account_setup_bank_manual_config> account_setup_bank_manual_configs, int batchSize) {

                        //account_setup_bank_manual_configClientService.createBatch(account_setup_bank_manual_configs,batchSize) ;

    }

    @Override
    public Account_setup_bank_manual_config get(Integer id) {
        Iaccount_setup_bank_manual_config clientModel = account_setup_bank_manual_configClientService.createModel();
        clientModel.setId(id);
        account_setup_bank_manual_configClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_setup_bank_manual_config get(Account_setup_bank_manual_config account_setup_bank_manual_config) {
        Account_setup_bank_manual_config retaccount_setup_bank_manual_config = this.get(account_setup_bank_manual_config.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_setup_bank_manual_config.getClass(), account_setup_bank_manual_config.getClass(), false);
        copier.copy(retaccount_setup_bank_manual_config, account_setup_bank_manual_config, null);
        return account_setup_bank_manual_config ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_setup_bank_manual_configClientService.removeBatch(account_setup_bank_manual_configs) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_setup_bank_manual_config> searchDefault(Account_setup_bank_manual_configSearchContext context) {
        List<Account_setup_bank_manual_config> list = new ArrayList<Account_setup_bank_manual_config>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config> clientModelList = account_setup_bank_manual_configClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_setup_bank_manual_config>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据银行账户查询
     */
    @Override
    public Page<Account_setup_bank_manual_config> selectByOdoo_res_partner_bank(Integer id){
        Account_setup_bank_manual_configSearchContext context = new Account_setup_bank_manual_configSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_setup_bank_manual_config> list = new ArrayList<Account_setup_bank_manual_config>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config> clientModelList = account_setup_bank_manual_configClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_setup_bank_manual_config>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_setup_bank_manual_config> selectByOdoo_create(Integer id){
        Account_setup_bank_manual_configSearchContext context = new Account_setup_bank_manual_configSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_setup_bank_manual_config> list = new ArrayList<Account_setup_bank_manual_config>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config> clientModelList = account_setup_bank_manual_configClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_setup_bank_manual_config>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_setup_bank_manual_config> selectByOdoo_write(Integer id){
        Account_setup_bank_manual_configSearchContext context = new Account_setup_bank_manual_configSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_setup_bank_manual_config> list = new ArrayList<Account_setup_bank_manual_config>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config> clientModelList = account_setup_bank_manual_configClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_setup_bank_manual_config clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_setup_bank_manual_config>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_setup_bank_manual_config convert2Model(Account_setup_bank_manual_config domain , Iaccount_setup_bank_manual_config model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_setup_bank_manual_configClientService.createModel() ;
        }

         if(domain.getJournal_idDirtyFlag())
            model.setJournal_id(domain.getJournal_id());
         if(domain.getLinked_journal_idDirtyFlag())
            model.setLinked_journal_id(domain.getLinked_journal_id());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getNew_journal_nameDirtyFlag())
            model.setNew_journal_name(domain.getNew_journal_name());
         if(domain.getNew_journal_codeDirtyFlag())
            model.setNew_journal_code(domain.getNew_journal_code());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCreate_or_link_optionDirtyFlag())
            model.setCreate_or_link_option(domain.getCreate_or_link_option());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getRelated_acc_typeDirtyFlag())
            model.setRelated_acc_type(domain.getRelated_acc_type());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getBank_nameDirtyFlag())
            model.setBank_name(domain.getBank_name());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getBank_idDirtyFlag())
            model.setBank_id(domain.getBank_id());
         if(domain.getQr_code_validDirtyFlag())
            model.setQr_code_valid(domain.getQr_code_valid());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getSanitized_acc_numberDirtyFlag())
            model.setSanitized_acc_number(domain.getSanitized_acc_number());
         if(domain.getAcc_typeDirtyFlag())
            model.setAcc_type(domain.getAcc_type());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getAcc_numberDirtyFlag())
            model.setAcc_number(domain.getAcc_number());
         if(domain.getBank_bicDirtyFlag())
            model.setBank_bic(domain.getBank_bic());
         if(domain.getAcc_holder_nameDirtyFlag())
            model.setAcc_holder_name(domain.getAcc_holder_name());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getRes_partner_bank_idDirtyFlag())
            model.setRes_partner_bank_id(domain.getRes_partner_bank_id());
        return model ;
    }

    public Account_setup_bank_manual_config convert2Domain( Iaccount_setup_bank_manual_config model ,Account_setup_bank_manual_config domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_setup_bank_manual_config();
        }

        if(model.getJournal_idDirtyFlag())
            domain.setJournal_id(model.getJournal_id());
        if(model.getLinked_journal_idDirtyFlag())
            domain.setLinked_journal_id(model.getLinked_journal_id());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getNew_journal_nameDirtyFlag())
            domain.setNew_journal_name(model.getNew_journal_name());
        if(model.getNew_journal_codeDirtyFlag())
            domain.setNew_journal_code(model.getNew_journal_code());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCreate_or_link_optionDirtyFlag())
            domain.setCreate_or_link_option(model.getCreate_or_link_option());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getRelated_acc_typeDirtyFlag())
            domain.setRelated_acc_type(model.getRelated_acc_type());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getBank_nameDirtyFlag())
            domain.setBank_name(model.getBank_name());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getBank_idDirtyFlag())
            domain.setBank_id(model.getBank_id());
        if(model.getQr_code_validDirtyFlag())
            domain.setQr_code_valid(model.getQr_code_valid());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getSanitized_acc_numberDirtyFlag())
            domain.setSanitized_acc_number(model.getSanitized_acc_number());
        if(model.getAcc_typeDirtyFlag())
            domain.setAcc_type(model.getAcc_type());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getAcc_numberDirtyFlag())
            domain.setAcc_number(model.getAcc_number());
        if(model.getBank_bicDirtyFlag())
            domain.setBank_bic(model.getBank_bic());
        if(model.getAcc_holder_nameDirtyFlag())
            domain.setAcc_holder_name(model.getAcc_holder_name());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getRes_partner_bank_idDirtyFlag())
            domain.setRes_partner_bank_id(model.getRes_partner_bank_id());
        return domain ;
    }


}
